import React ,{Suspense} from 'react'
import {BrowserRouter,Route,Routes,Navigate} from "react-router-dom"
import {routes} from "./routes"
import {routerItem} from "../interface"


function index() {
    const mapRouter=(route:routerItem[])=>{
        return route.map((v,i)=>{
            return v.path?
            <Route key={i} path={v.path} element={v.element}>
                {
                    v.children&&mapRouter(v.children)
                }
            </Route>:
            <Route key={i} path={v.from} element={<Navigate to={v.to}/>}></Route>
        })
    }
    return (
        <Suspense  fallback={<h1>加载中....</h1>}>
            <BrowserRouter>
                <Routes>
                    {
                        mapRouter(routes)
                    }
                </Routes>
            </BrowserRouter>
        </Suspense>
    )
}

export default index
